<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   家居商铺缓存函数($$)*/

!defined('Q_PATH') && exit;

class Jiaju_Cacheshop{

	public static function cacheIndex($nId){
		$arrDir=C::getDisDir($nId);
		$arrDatas=Q::cache('shop_'.$arrDir[1].'_'.md5($arrDir[0]),'',
			array('encoding_filename'=>false,
				'cache_path'=>WINDSFORCE_PATH.'/~@~/data/jiaju/shop/'.$arrDir[0]
			)
		);
		
		// 缓存商铺首页数据
		if($arrDatas===false){
			$arrDatas=array();

			// 最新订单
			$arrDatas['order']=Model::F_('jiajuorder')
				->setColumns('jiajuorder_realname,jiajuorder_mobile,jiajuorder_qq,create_dateline')
				->where(array('jiajucompany_id'=>$nId,'jiajuorder_status'=>1))
				->order('jiajuorder_id DESC')
				->limit(0,20)
				->getAll();

			// 最新点评
			$arrDatas['comment']=Model::F_('jiajucompanycomment')
				->setColumns('user_id,create_dateline,jiajucompanycomment_name,jiajucompanycomment_level,jiajucompanycomment_level1,jiajucompanycomment_level2,jiajucompanycomment_level3,jiajucompanycomment_level4,jiajucompanycomment_level5,jiajucompanycomment_content,jiajucompanycomment_replytime,jiajucompanycomment_replycontent,jiajucompanycomment_replytime')
				->where(array('jiajucompany_id'=>$nId,'jiajucompanycomment_status'=>1))
				->order('jiajucompanycomment_id DESC')
				->limit(0,10)
				->getAll();
			
			// 最新留言
			$arrDatas['guestbook']=Model::F_('jiajucompanyguestbook')
				->setColumns('jiajucompanyguestbook_name,create_dateline,jiajucompanyguestbook_content,jiajucompanyguestbook_replytime,jiajucompanyguestbook_replycontent,jiajucompanyguestbook_replytime')
				->where(array('jiajucompany_id'=>$nId,'jiajucompanyguestbook_status'=>1))
				->order('jiajucompanyguestbook_id DESC')
				->limit(0,10)
				->getAll();
			
			// 最新作品
			$arrDatas['case']=Model::F_('jiajucase')
				->setColumns('jiajucase_id,jiajucase_thumb,jiajucase_title')
				->where(array('jiajucompany_id'=>$nId,'jiajucase_status'=>1))
				->order('jiajucase_id DESC')
				->limit(0,6)
				->getAll();
			
			// 最新套餐
			$arrDatas['package']=Model::F_('jiajupackage')
				->setColumns('jiajupackage_id,jiajupackage_title,jiajupackage_thumb,jiajupackage_price,jiajupackage_firstprice')
				->where(array('jiajucompany_id'=>$nId,'jiajupackage_status'=>1))
				->order('jiajupackage_id DESC')
				->limit(0,6)
				->getAll();
			
			// 最新活动
			$arrDatas['event']=Model::F_('jiajuevent','@A')
				->setColumns('A.jiajuevent_id,A.jiajuevent_title,A.jiajuevent_starttime,A.jiajuevent_endtime,A.jiajuevent_viewnum,A.jiajuevent_description,A.jiajuevent_thumb')
				->where(array('A.jiajucompany_id'=>$nId,'A.jiajuevent_status'=>1))
				->order('A.jiajuevent_id DESC')
				->getOne();
			
			// 最新案例
			$arrDatas['anli']=Model::F_('jiajuanli')
				->setColumns('jiajuanli_link,jiajuanli_title')
				->where(array('jiajucompany_id'=>$nId,'jiajuanli_status'=>1))
				->order('jiajuanli_id DESC')
				->limit(0,8)
				->getAll();
			
			// 最新日记
			$arrDatas['diary']=Model::F_('jiajudiary')
				->setColumns('jiajudiary_link,jiajudiary_title')
				->where(array('jiajucompany_id'=>$nId,'jiajudiary_status'=>1))
				->order('jiajudiary_id DESC')
				->limit(0,8)
				->getAll();

			// 最新视频
			$arrDatas['video']=Model::F_('jiajuvideo')
				->setColumns('jiajuvideo_id,jiajuvideo_title')
				->where(array('jiajucompany_id'=>$nId,'jiajuvideo_status'=>1))
				->order('jiajuvideo_id DESC')
				->limit(0,8)
				->getAll();
			
			// 最新在建工地
			$arrDatas['build']=Model::F_('jiajubuild')
				->setColumns('jiajubuild_id,jiajubuild_thumb,jiajubuild_title')
				->where(array('jiajucompany_id'=>$nId,'jiajubuild_status'=>1))
				->order('jiajubuild_id DESC')
				->limit(0,6)
				->getAll();
			
			// 最新设计师
			$arrDatas['designer']=Model::F_('jiajudesigner')
				->setColumns('user_id,jiajudesigner_name,jiajudesigner_type,jiajudesigner_id')
				->where(array('jiajucompany_id'=>$nId,'jiajudesigner_status'=>1))
				->order('jiajudesigner_type DESC,jiajudesigner_sort ASC,jiajudesigner_id DESC')
				->limit(0,4)
				->getAll();

			Q::cache('shop_'.$arrDir[1].'_'.md5($arrDir[0]),$arrDatas,
				array('encoding_filename'=>false,
					'cache_path'=>WINDSFORCE_PATH.'/~@~/data/jiaju/shop/'.$arrDir[0]
				)
			);
		}

		return $arrDatas;
	}
	
	public static function cacheServices($nId){
		$arrDir=C::getDisDir($nId);
		$arrDatas=Q::cache('shopservices_'.$arrDir[1].'_'.md5($arrDir[0]),'',
			array('encoding_filename'=>false,
				'cache_path'=>WINDSFORCE_PATH.'/~@~/data/jiaju/shop/'.$arrDir[0]
			)
		);
		
		// 缓存商铺服务数据
		if($arrDatas===false){
			$arrDatas=array();

			// 读取服务区域
			$arrDatas['district']=Model::F_('jiajucompanydistrict','@A')->setColumns('A.*')
				->setColumns('A.district_id')
				->where(array('A.jiajucompany_id'=>$nId))
				->join(Q::C('DB_PREFIX').'district AS B','B.district_name','A.district_id=B.district_id')
				->getAll();

			// 读取家庭装修和商业装修等
			$arrDatas['homeclass']=Model::F_('jiajucompanyhomeclass','@A')
				->setColumns('A.jiajucompanyclass_id')
				->where(array('A.jiajucompany_id'=>$nId))
				->join(Q::C('DB_PREFIX').'jiajucompanyclass AS B','B.jiajucompanyclass_name','A.jiajucompanyclass_id=B.jiajucompanyclass_id')
				->getAll();
			
			$arrDatas['businessclass']=Model::F_('jiajucompanybusinessclass','@A')
				->setColumns('A.jiajucompanyclass_id')
				->where(array('A.jiajucompany_id'=>$nId))
				->join(Q::C('DB_PREFIX').'jiajucompanyclass AS B','B.jiajucompanyclass_name','A.jiajucompanyclass_id=B.jiajucompanyclass_id')
				->getAll();
			
			$arrDatas['styleclass']=Model::F_('jiajucompanystyleclass','@A')
				->setColumns('A.jiajucompanyclass_id')
				->where(array('A.jiajucompany_id'=>$nId))
				->join(Q::C('DB_PREFIX').'jiajucompanyclass AS B','B.jiajucompanyclass_name','A.jiajucompanyclass_id=B.jiajucompanyclass_id')
				->getAll();

			Q::cache('shopservices_'.$arrDir[1].'_'.md5($arrDir[0]),$arrDatas,
				array('encoding_filename'=>false,
					'cache_path'=>WINDSFORCE_PATH.'/~@~/data/jiaju/shop/'.$arrDir[0]
				)
			);
		}

		return $arrDatas;
	}

	public static function cacheVerify($nId){
		$arrDir=C::getDisDir($nId);
		$arrDatas=Q::cache('shopverify_'.$arrDir[1].'_'.md5($arrDir[0]),'',
			array('encoding_filename'=>false,
				'cache_path'=>WINDSFORCE_PATH.'/~@~/data/jiaju/shop/'.$arrDir[0]
			)
		);
		
		// 缓存商铺服务数据
		if($arrDatas===false){
			$arrDatas=array();

			// 读取荣誉证书
			$arrDatas=Model::F_('jiajucompanyverifyimg')
				->setColumns('jiajucompanyverifyimg_file')
				->where(array('jiajucompany_id'=>$nId))
				->getAll();

			Q::cache('shopverify_'.$arrDir[1].'_'.md5($arrDir[0]),$arrDatas,
				array('encoding_filename'=>false,
					'cache_path'=>WINDSFORCE_PATH.'/~@~/data/jiaju/shop/'.$arrDir[0]
				)
			);
		}

		return $arrDatas;
	}

	public static function cacheBanner($nId){
		$arrDir=C::getDisDir($nId);
		$arrDatas=Q::cache('shopbanner_'.$arrDir[1].'_'.md5($arrDir[0]),'',
			array('encoding_filename'=>false,
				'cache_path'=>WINDSFORCE_PATH.'/~@~/data/jiaju/shop/'.$arrDir[0]
			)
		);
		
		// 缓存商铺广告数据
		if($arrDatas===false){
			$arrDatas=array();

			// 读取广告数据
			$arrDatas=Model::F_('jiajucompanybanner','jiajucompany_id=?',$nId)
				->setColumns('jiajucompanybanner_filename,jiajucompanybanner_filetitle,jiajucompanybanner_link')
				->getAll();

			Q::cache('shopbanner_'.$arrDir[1].'_'.md5($arrDir[0]),$arrDatas,
				array('encoding_filename'=>false,
					'cache_path'=>WINDSFORCE_PATH.'/~@~/data/jiaju/shop/'.$arrDir[0]
				)
			);
		}

		return $arrDatas;
	}

}
